package com.wn.service.controller;

import com.wn.bean.User;
import com.wn.service.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yellow docter
 * @since 2022-08-23
 */
@RestController
@RequestMapping("/user")
@Api(tags = "user的服务提供者")
@Slf4j
public class UserController  {

    @Autowired
    private IUserService userService;

    @ApiOperation("通过id查询的方法")
    @GetMapping("{uid}")
    public User findUserById(@PathVariable Integer uid){
        return userService.getById(uid);
    }

    @ApiOperation("添加的方法")
    @PostMapping
    public String saveUser(@RequestBody User user){

        boolean save = userService.save(user);
        return save ? "success":"fail";
    }

    @ApiOperation("通过user修改的方法")
    @PutMapping
    public String updateUser(@RequestBody User user){

        boolean save = userService.updateById(user);
        return save ? "success":"fail";
    }

    @ApiOperation("通过id删除的方法")
    @DeleteMapping("{uid}")
    public String deleteById(@PathVariable Integer uid){
        log.info("请求发送过来了...{}",uid);
        boolean save = userService.removeById(uid);
        return save ? "success":"fail";
    }


}
